# 2024/1/31 11:21 HFL
import re

import requests
import unittest,pytest

from common.AMD5 import Bmd5


class Test_ApiChandaoxinzengTestCase(unittest.TestCase):


    def setUp(self):
        self.s = requests.session()
        s1 = requests.session()
        url = 'http://192.168.12.7:8080/zentao/user-login.html'
        res = s1.get(url=url)
        cerify = re.findall("name='verifyRand' id='verifyRand' value='(.*?)'", res.text)
        paw = Bmd5('admin123.')
        mity = Bmd5(paw + cerify[0])
        data = {'account': 'admin',
                'password': mity,  # b3490f85cf297f58c03767578aafdbc6
                'passwordStrength': 1,
                'referer': '/pro/',
                'verifyRand': cerify[0],
                'keepLogin': 0
                }
        res2 = s1.post(url=url, data=data)
        rrs = s1.post(url='http://192.168.12.7:8080/zentao/my/')
        if 'admin' in rrs.text:
            print('登录成功')
        else:
            print('登录失败')

    def tearDown(self):
        pass

    def test_apichandaoxinzeng(self):
        url = 'http://192.168.12.7:8080/zentao/project-create.html'
        data = {
            'name': 'tets9991',
            'code': 'tets9991',
            'begin': '2024-01-31',
            'end': '2024-02-06',
        }
        headers = {
            "Cookie": "lang=zh-cn; device=desktop; theme=default; keepLogin=on; za=admin; preBranch=0; preProductID=1; lastProduct=0; goback=%7B%22product%22%3A%22http%3A%5C%2F%5C%2F192.168.12.7%3A5674%5C%2Fzentao%5C%2Fprogram-browse.html%22%2C%22project%22%3A%22http%3A%5C%2F%5C%2F192.168.12.7%3A5674%5C%2Fzentao%5C%2Fproject-bug-11.html%22%2C%22admin%22%3A%22http%3A%5C%2F%5C%2F192.168.12.7%3A5674%5C%2Fzentao%5C%2Fbackup%5C%2F%22%2C%22execution%22%3A%22http%3A%5C%2F%5C%2F192.168.12.7%3A5674%5C%2Fzentao%5C%2Fproject-browse.html%22%7D; tab=my; zentaosid=d3eb9b0ed0d804652b0d0ea707d81d61; zp=44ade467a04280fa1e2582f39cd5dea6ff5cccb5; from=doc; lastProject=1; preProjectID=1; moduleBrowseParam=0; productBrowseParam=0; projectTaskOrder=status%2Cid_desc; windowWidth=1360; windowHeight=848; remember-me=YWRtaW46MTcwNzA0MDM2MjU4ODowNzE0MTZmNmRmNzQxNmIzNmIxZDhhN2M0ZTFkZGE4YTdjZjU4ZGNmOTIyMjcwN2Q2MTQ0MjJjMjMwYzAxOGZj"}
        res = self.s.post(url=url, data=data, headers=headers)
        print(res.text)
        self.assertEqual(1,1)


# if __name__ == '__main__':
#     pytest.main(['-vs','apichandaoxinzeng.py','--html=D:\\Python_study\\pytest_requests\\report\\20240131002111.html'])
